package informed.samples;

import informed.io.ReadSparseMatrix;
import informed.matrix.SparseVector;

import java.util.ArrayList;

import cern.colt.matrix.DoubleMatrix1D;
import cern.colt.matrix.DoubleMatrix2D;

public class VectorValueSample implements Sample{
	
	public DoubleMatrix1D x; // Dense Vector (this is deprecated)
	public SparseVector v; // Sparse Vector (use only one, not both)
	public double y; // Value
	public int i;
	public int j;
	
	public static ArrayList<Sample> loadSamples(String fileX, String fileY){
		ReadSparseMatrix reader = new ReadSparseMatrix();
		DoubleMatrix2D x = reader.read(fileX);
		DoubleMatrix2D y = reader.read(fileY);
		ArrayList<Sample> samples = new ArrayList<Sample>();
		for(int i = 0; i < y.rows(); i++){
			for(int j = 0; j < y.columns(); j++){
				VectorValueSample s = new VectorValueSample();
				s.i = i; s.j = j;
				s.y = y.getQuick(i, j);
				s.x = x.viewColumn(j);
				samples.add(s);
			}
		}
		return samples;
	}
	
	public static ArrayList<Sample> loadSparseSamples(String fileX, String fileY){
		ReadSparseMatrix reader = new ReadSparseMatrix();
		DoubleMatrix2D y = reader.read(fileY);
		ArrayList<SparseVector> vectors = reader.readVectors(fileX);
		ArrayList<Sample> samples = new ArrayList<Sample>();
		for(int i = 0; i < y.rows(); i++){
			for(int j = 0; j < y.columns(); j++){
				VectorValueSample s = new VectorValueSample();
				s.i = i; s.j = j;
				s.y = y.getQuick(i, j);
				s.v = vectors.get(j);
				samples.add(s);
			}
		}
		return samples;
	}

}
